package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;

import java.util.List;

import com.company.project.common.utils.DataResult;
import com.company.project.entity.MatchTeamEntity;
import com.company.project.service.MatchTeamService;

/**
 * 团队表
 *
 * @author ls
 * @email *****@mail.com
 * @date 2021-02-02 20:34:19
 */
@Controller
@RequestMapping("/")
@Api(tags = "比赛队伍模块")
public class MatchTeamController extends BaseController{
    @Autowired
    private MatchTeamService matchTeamService;

    /*************************后端展示***********************************/
    /**
    * 跳转到页面
    */
    @GetMapping("/index/matchTeam")
    public String matchTeam() {
        return "matchteam/list";
        }

    //@ApiOperation(value = "新增")
    @PostMapping("matchTeam/add")
    @RequiresPermissions("matchTeam:add")
    @ResponseBody
    public DataResult add(@RequestBody MatchTeamEntity matchTeam){
        matchTeamService.save(matchTeam);
        return DataResult.success();
    }

    //@ApiOperation(value = "删除")
    @DeleteMapping("matchTeam/delete")
    @RequiresPermissions("matchTeam:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        matchTeamService.removeByIds(ids);
        return DataResult.success();
    }

    //@ApiOperation(value = "更新")
    @PutMapping("matchTeam/update")
    @RequiresPermissions("matchTeam:update")
    @ResponseBody
    public DataResult update(@RequestBody MatchTeamEntity matchTeam){
        matchTeamService.updateById(matchTeam);
        return DataResult.success();
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    //@ApiOperation(value = "查询分页数据")
    @PostMapping("matchTeam/listByPage")
    @RequiresPermissions("matchTeam:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody MatchTeamEntity matchTeam){
        Page page = new Page(matchTeam.getPage(), matchTeam.getLimit());
        LambdaQueryWrapper<MatchTeamEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(MatchTeamEntity::getId, matchTeam.getId());
        IPage<MatchTeamEntity> iPage = matchTeamService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
